<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css"
          href="easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="easyui/demo/demo.css">
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="myjs/rukuyb.js"></script>
    <script type="text/javascript" src="myjs/path.js"></script>
    <script type="text/javascript" src="myjs/loader.js"></script>
    <!-- <script type="text/javascript" src="js/jquery.jqprint-0.3.js"></script>
    <script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script> -->
</head>

<body class="easyui-layout">

<div id="tb">
    选择时间: <input id='db' style="width: 120px"> 关键词:
    <input id="tree" class="easyui-combotree"
           style="width: 160px;"/>
    <input id="kuanhao" class="easyui-searchbox"
           data-options="searcher:qq,prompt:'请输入款号关键词'">
    <a id="dlink"></a> <a iconCls="icon-save"
                          class="easyui-linkbutton" type="button"
                          onclick="tableToExcel('tablename', 'name')">导出Excel</a>
</div>
<table class="easyui-datagrid" id="cxdm">

</table>
</body>
</html>
<script>
    $(function () {
        findTree();
        $("#tree").combotree({
            onSelect: function (node) {
                var qtime = $('#db').val();
                if (qtime != '' && qtime != null) {
                    var curDate = new Date(qtime.replace(/-/, "/"))
                    var curMonth = curDate.getMonth();
                    curDate.setMonth(curMonth + 1);
                    curDate.setDate(0);
                    var days = curDate.getDate();// 获取选择时间有多少天
                }

                $('#cxdm').datagrid({
                    url: path + '/report/gtRukuyuebao.do',
                    queryParams: {
                        jgid: node.id,
                        selectText: $("#kuanhao").val(),// 需要查询的商品款号
                        monSearch: qtime,
                    }
                })
            },
            onLoadSuccess: function (node, data) {
                $("#tree").combotree('setValue', data[0].id);
                load();
            }
        });
    })

    function qq() {
        load();
    }

    //加载树
    function findTree() {
        //加载combotree
        $.ajax({
            url: path + '/jg/tree.do',
            dataType: 'json',
            success: function (data) {
                if (data.code != 400) {
                    $('#tree').combotree('loadData', data.rows);
                } else {
                    $.messager.alert('提示', data.msg);
                }
            }
        })

    }

    $(document).ready(function () {
        $('#kuanhao').next('span').find('input').focus()
    });

    $('#kuanhao').textbox({
        inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
            keyup: function (event) {
                if (event.keyCode == 13) {
                    load();
                    $('#kuanhao').next('span').find('input').focus()
                }
            }
        })
    });
    var myDate = new Date();
    var year = myDate.getFullYear();
    var month = myDate.getMonth() + 1;
    if (month >= 10) {
        var sj = year + '-' + month;
    } else {
        var sj = year + '-' + "0" + month;
    }
    $("#db").val(sj);


    function load() {
        var qtime = $('#db').val();
        if (qtime != '' && qtime != null) {
            var curDate = new Date(qtime.replace(/-/, "/"))
            var curMonth = curDate.getMonth();
            curDate.setMonth(curMonth + 1);
            curDate.setDate(0);
            var days = curDate.getDate();// 获取选择时间有多少天
        }
        $("#cxdm").datagrid({
            url: path + '/report/gtRukuyuebao.do',
            queryParams: {
                selectText: $("#kuanhao").val(),// 需要查询的商品款号
                monSearch: qtime,
                jgid: $("#tree").combotree("getValue"),
            }
        })
    }

    //加载数据
    $('#cxdm').datagrid({
        width: 'auto',
        toolbar: '#tb',
        striped: true,
        singleSelect: true,
        loadMsg: '数据加载中请稍后……',
        fitColumns: true,
        fit: true,//自动补全
        dataType: "json",
        columns: [[{
            field: 'product',
            title: '商品款号',
            align: 'center',
            width: 80
        }, {
            field: 'zongji',
            title: '月累计',
            align: 'center',
            width: 25
        }, {
            field: 'shuliang1',
            title: '1',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang2',
            title: '2',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang3',
            title: '3',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang4',
            title: '4',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang5',
            title: '5',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang6',
            title: '6',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang7',
            title: '7',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang8',
            title: '8',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang9',
            title: '9',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang10',
            title: '10',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang11',
            title: '11',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang12',
            title: '12',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang13',
            title: '13',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang14',
            title: '14',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang15',
            title: '15',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang16',
            title: '16',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang17',
            title: '17',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang18',
            title: '18',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang19',
            title: '19',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang20',
            title: '20',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang21',
            title: '21',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang22',
            title: '22',
            align: 'center',
            width: 20
        }, {
            field: '23',
            title: '23',
            align: 'center',
            width: 20
        }, {
            field: '24',
            title: '24',
            align: 'center',
            width: 20
        }, {
            field: '25',
            title: '25',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang26',
            title: '26',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang27',
            title: '27',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang28',
            title: '28',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang29',
            title: '29',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang30',
            title: '30',
            align: 'center',
            width: 20
        }, {
            field: 'shuliang31',
            title: '31',
            align: 'center',
            width: 20
        }, {
            field: 'productName',
            title: '名称',
            align: 'center',
            width: 25
        }, {
            field: 'pinpai',
            title: '品牌',
            align: 'center',
            width: 25
        }]],
        loadFilter: function (data) {
            var rows = eval("(" + data.rows + ")");
            return rows;
        },
        onLoadSuccess: function (data) {
            var qtime = $('#db').val();
            if (qtime != '' && qtime != null) {
                var curDate = new Date(qtime.replace(/-/, "/"))
                var curMonth = curDate.getMonth();
                curDate.setMonth(curMonth + 1);
                curDate.setDate(0);
                var days = curDate.getDate();// 获取选择时间有多少天
            }
            if (days == 28) {
                $("#cxdm").datagrid("hideColumn", "shuliang29"); // 设置隐藏列
                $("#cxdm").datagrid("hideColumn", "shuliang30"); // 设置隐藏列
                $("#cxdm").datagrid("hideColumn", "shuliang31"); // 设置隐藏列
            } else if (days == 29) {
                $("#cxdm").datagrid("hideColumn", "shuliang30"); // 设置隐藏列
                $("#cxdm").datagrid("hideColumn", "shuliang31"); // 设置隐藏列
            } else if (days == 30) {
                $("#cxdm").datagrid("hideColumn", "shuliang31"); // 设置隐藏列
            }
            $('#kuanhao').next('span').find('input').focus();
            disLoad();//隐藏加载中。。
        }
    });
</script>

